﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MixScript.BLL.Accounting
{
    public class ListGeneralJournal
    {

        private List<GeneralJournal> _ListOfJournal;

        public List<GeneralJournal> ListOfJournal
        {
            get
            {
                return _ListOfJournal;
            }
            set
            {
                if (_ListOfJournal == value)
                    return;
                _ListOfJournal = value;
            }
        }

        public Int32 GetDebit()
        {
            Int32 Result = 0;
            for (int i = 0; i < ListOfJournal.Count; i++)
            {
                Result += ListOfJournal[i].debit;

            }

            return Result;
        }
        public Int32 GetCredit()
        {
            Int32 Result1 = 0;
            for (int i = 0; i < ListOfJournal.Count; i++)
            {
                Result1 += ListOfJournal[i].credit;
            }
            if (Result1 < 0)
                Result1 = Result1 * -1;
            return Result1;
        }
        public Int32 GetTotal()
        {
            Int32 Result = 0;
            for (int i = 0; i < ListOfJournal.Count; i++)
            {
                Result += (ListOfJournal[i].debit - ListOfJournal[i].credit);
            }
            if (Result < 0)
                Result = Result * -1;
            return Result;

        }
        public GeneralJournal GetJournal(int id)
        {
            for (int i = 0; i < ListOfJournal.Count; i++)
            {
                if (ListOfJournal[i].id == id)
                    return ListOfJournal[i];
            }
            return null;
        }
        public ListGeneralJournal DeleteJournal(int id)
        {
            ListGeneralJournal gj = new ListGeneralJournal();
            gj.ListOfJournal = new List<GeneralJournal>();
 
            for (int i = 0; i < ListOfJournal.Count; i++)
            {
                if (ListOfJournal[i].id != id)
                    gj.ListOfJournal.Add(ListOfJournal[i]);
            }
            return gj;
        }
        public ListGeneralJournal UpdateJournal(int id, GeneralJournal journal)
        {
            ListGeneralJournal gj = new ListGeneralJournal();
            gj.ListOfJournal = new List<GeneralJournal>();
            for (int i = 0; i < ListOfJournal.Count; i++)
            {
                if (ListOfJournal[i].id != id)
                    gj.ListOfJournal.Add(ListOfJournal[i]);
                else
                    gj.ListOfJournal.Add(journal);
            }
            return gj;
        }

    }
}
